package com.gzr.collection.set;

import com.gzr.collection.set.entity.Student;

import java.util.HashSet;

/**
 * HashSet集合元素去重操作 在学生类上重新equals 和 hashCode 即可
 */
public class SetDemo01 {
    public static void main(String[] args) {
        HashSet<Student> hashSet = new HashSet<>();
        Student s1 = new Student("张三", 18, "北京");
        Student s2 = new Student("李四", 20, "上海");
        Student s3 = new Student("张三", 18, "北京");
        Student s4 = new Student("李四", 20, "上海");

        hashSet.add(s1);
        hashSet.add(s2);
        hashSet.add(s3);
        hashSet.add(s4);

        System.out.println(hashSet);



    }
}
